/*  1:   */ package org.jetbrains.lang.manifest.header.impl;
/*  2:   */ 
/*  3:   */

import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiMethodUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.lang.manifest.ManifestBundle;
import org.jetbrains.lang.manifest.header.HeaderParser;
import org.jetbrains.lang.manifest.psi.Header;
import org.jetbrains.lang.manifest.psi.HeaderValue;
import org.jetbrains.lang.manifest.psi.HeaderValuePart;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */
/* 17:   */
/* 18:   */
/* 19:   */
/* 20:   */ 
/* 21:   */ public class ClassReferenceParser
/* 22:   */   extends StandardHeaderParser
/* 23:   */ {
/* 24:37 */   public static final HeaderParser INSTANCE = new ClassReferenceParser();
/* 25:   */   
/* 26:   */   @NotNull
/* 27:   */   public PsiReference[] getReferences(@NotNull HeaderValuePart paramHeaderValuePart)
/* 28:   */   {
/* 29:42 */     if (paramHeaderValuePart == null) {
/* 30:42 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "getReferences" }));
/* 31:   */     }
/* 32:42 */     final Module localModule = ModuleUtilCore.findModuleForPsiElement(paramHeaderValuePart);
/* 33:   */     Object localObject;
/* 34:44 */     if (localModule != null) {
/* 35:45 */       localObject = new JavaClassReferenceProvider()
/* 36:   */       {
/* 37:   */         public GlobalSearchScope getScope(Project paramAnonymousProject)
/* 38:   */         {
/* 39:48 */           return GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(localModule);
/* 40:   */         }
/* 41:   */       };
/* 42:   */     } else {
/* 43:53 */       localObject = new JavaClassReferenceProvider();
/* 44:   */     }
/* 45:55 */     PsiReference[] tmp75_72 = ((JavaClassReferenceProvider)localObject).getReferencesByElement(paramHeaderValuePart);
/* 46:55 */     if (tmp75_72 == null) {
/* 47:55 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "getReferences" }));
/* 48:   */     }
/* 49:55 */     return tmp75_72;
/* 50:   */   }
/* 51:   */   
/* 52:   */   public boolean annotate(@NotNull Header paramHeader, @NotNull AnnotationHolder paramAnnotationHolder)
/* 53:   */   {
/* 54:60 */     if (paramHeader == null) {
/* 55:60 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "annotate" }));
/* 56:   */     }
/* 57:60 */     if (paramAnnotationHolder == null) {
/* 58:60 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "annotate" }));
/* 59:   */     }
/* 60:60 */     HeaderValue localHeaderValue = paramHeader.getHeaderValue();
/* 61:61 */     if (!(localHeaderValue instanceof HeaderValuePart)) {
/* 62:61 */       return false;
/* 63:   */     }
/* 64:63 */     PsiReference[] arrayOfPsiReference = localHeaderValue.getReferences();
/* 65:64 */     if (arrayOfPsiReference.length == 0)
/* 66:   */     {
/* 67:65 */       paramAnnotationHolder.createErrorAnnotation(((HeaderValuePart)localHeaderValue).getHighlightingRange(), ManifestBundle.message("header.reference.invalid", new Object[0]));
/* 68:66 */       return true;
/* 69:   */     }
/* 70:69 */     for (int i = 0; i < arrayOfPsiReference.length; i++)
/* 71:   */     {
/* 72:70 */       PsiReference localPsiReference = arrayOfPsiReference[i];
/* 73:71 */       PsiElement localPsiElement = localPsiReference.resolve();
/* 74:72 */       if (localPsiElement == null)
/* 75:   */       {
/* 76:73 */         TextRange localTextRange = localPsiReference.getRangeInElement().shiftRight(localHeaderValue.getTextOffset());
/* 77:74 */         paramAnnotationHolder.createErrorAnnotation(localTextRange, ManifestBundle.message("header.reference.unknown", new Object[0]));
/* 78:75 */         return true;
/* 79:   */       }
/* 80:78 */       if ((i == arrayOfPsiReference.length - 1) && 
/* 81:79 */         (checkClass(localPsiReference, localPsiElement, paramAnnotationHolder))) {
/* 82:80 */         return true;
/* 83:   */       }
/* 84:   */     }
/* 85:85 */     return false;
/* 86:   */   }
/* 87:   */   
/* 88:   */   protected boolean checkClass(@NotNull PsiReference paramPsiReference, @NotNull PsiElement paramPsiElement, @NotNull AnnotationHolder paramAnnotationHolder)
/* 89:   */   {
/* 90:89 */     if (paramPsiReference == null) {
/* 91:89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "checkClass" }));
/* 92:   */     }
/* 93:89 */     if (paramPsiElement == null) {
/* 94:89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "checkClass" }));
/* 95:   */     }
/* 96:89 */     if (paramAnnotationHolder == null) {
/* 97:89 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "2", "org/jetbrains/lang/manifest/header/impl/ClassReferenceParser", "checkClass" }));
/* 98:   */     }
/* 99:89 */     if (((paramPsiElement instanceof PsiClass)) && (PsiMethodUtil.hasMainMethod((PsiClass)paramPsiElement))) {
/* :0:90 */       return false;
/* :1:   */     }
/* :2:93 */     TextRange localTextRange = paramPsiReference.getRangeInElement().shiftRight(paramPsiReference.getElement().getTextOffset());
/* :3:94 */     paramAnnotationHolder.createErrorAnnotation(localTextRange, ManifestBundle.message("header.main.class.invalid", new Object[0]));
/* :4:95 */     return true;
/* :5:   */   }
/* :6:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.lang.manifest.header.impl.ClassReferenceParser

 * JD-Core Version:    0.7.0.1

 */